﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public static class Int
    {
        /// <summary>
        /// 扩展类和扩展方法必须是静态的，扩展方法的第一个参数必须为原有类自身，this关键字是必须的
        /// </summary>

        public static int ToIsNULLInt(this object self)
        {
            int rst = 0;
            if (self == null)
            {
                return 0;
            }
            try
            {
                rst = Convert.ToInt32(self);

            }
            catch (Exception)
            {
                return 0;
            }
            return rst;
        }

        public static int ToIsNULLInt(this object self,int defau)
        {
            int rst = defau;
            if (self == null)
            {
                return defau;
            }
            try
            {
                rst = Convert.ToInt32(self);

            }
            catch (Exception)
            {
                return defau;
            }
            return rst;
        }
    }
}
